import unittest,requests


class weidu(unittest.TestCase):
    # #register 注册
    # def test_weidu_01_register(self):
    #     url='http://10.59.9.18/small/user/v1/register'
    #     json={'phone':'17733058407','pwd':'li123456'}
    #     register=requests.post(url=url,json=json)
    #     print(register.json())

    sessionId=None
    userId=None
    #login 登录
    def test_weidu_02_login(self):
        url='http://10.59.9.18/small/user/v1/login'
        json = {'phone': '17733058407', 'pwd': 'li123456'}
        login=requests.post(url=url,json=json)
        print(login.json())
        weidu.sessionId=login.json()['result']['sessionId']
        print(weidu.sessionId)
        weidu.userId = login.json()['result']['userId']
        print(weidu.userId)

    #commodityList 商品列表
    def test_weidu_03_commodityList(self):
        commodityId=None
        url='http://10.59.9.18/small/commodity/v1/commodityList'
        commodityList=requests.get(url=url)
        print(commodityList.json())
        weidu.commodityId=commodityList.json()['result']['rxxp']['commodityList'][0]['commodityId']
        print(weidu.commodityId)

    #commodityId 商品详情
    def test_weidu_04_commodityId(self):
        url='http://10.59.9.18/small/commodity/v1/findCommodityDetailsById'
        params = {
            'commodityId': 7,
            'sessionId': weidu.sessionId
        }
        commodityId=requests.get(url=url,params=params)
        print(commodityId.json())

    #Commodity 商品评论
    def test_weidu_05_Commodity(self):
        url='http://10.59.9.18/small/commodity/v1/CommodityCommentList'
        params = {
            'commodityId': 7,
            'page': 1,
            'count':5
        }
        Commodity=requests.get(url=url,params=params)
        print(Commodity.json())


if __name__ == '__main__':
    unittest.main()